package typechecker.ast.term;

import java.util.HashMap;
import java.util.Map;

import typechecker.ast.type.TypeExpression;

public class CaseAnalisys extends Expression{
	private Map<TermVariable, Expression > branches =  new HashMap<TermVariable, Expression>();
	private Expression exp;
	private TypeExpression texp;
	
	public CaseAnalisys(Expression exp, TypeExpression texp) {
		this.exp = exp;
		this.texp = texp;
	}
	
	public void put(TermVariable tvar , Expression exp){
		this.branches.put(tvar, exp);
	}
	
	public Expression get(TermVariable tvar){
		return this.branches.get(tvar);
	}

	@Override
	public String preetyPrint() {
		String ret = "case<" + texp.preetyPrint() + "> " + exp.preetyPrint() + " of {\n";
		for( Map.Entry<TermVariable, Expression> branch : branches.entrySet()){
			ret += branch.getKey().preetyPrint() + " => " + branch.getValue().preetyPrint() + ";\n";
		}
		ret += "}";
		return ret;
	}
	public Expression getExp() {
		return exp;
	}
	
	public TypeExpression getType() {
		return texp;
	}
	
	public Map<TermVariable, Expression> getBranches() {
		return branches;
	}
}
